# -*- coding:utf-8 -*-
# @FileName  :adhcc_0_setup.py
# @Time      :2020/12/25 14:54
# @Author    :Zhoujirong
# @Desc      : 初始化测试用的用户

from common.log import Log
from biz.flow.role import RoleRequest
from biz.flow.user import UserRequest
from biz.flow.per_credit_user import PerCreditUserRequest
from biz.cases.base_case import BaseCase
from common.utils import get_redis

class TestSetUpUserMenu(BaseCase):
    '''初始化用户、菜单权限'''
    data_file_name = 'setup.yaml'

    @classmethod
    def setUpClass(cls):
        cls.redis = get_redis()
        cls.cookie = BaseCase().get_token_first()

    def credit_user_getpage_api(self):
        '''检索接口用户'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_creditName = self.file_data.get('creditName_api')
        search_LIKE_creditUser = self.file_data.get('creditUser_api')
        search_LIKE_creditOrgCode = self.file_data.get('creditOrgCode')
        search_EQ_userClass = self.file_data.get('userClass')
        search_IN_deptCode = self.file_data.get('deptCode')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        ret = PerCreditUserRequest.per_getpage(curPage, maxSize, search_LIKE_creditName, search_LIKE_creditUser,
                                               search_LIKE_creditOrgCode, search_EQ_userClass, search_IN_deptCode,
                                               search_EQ_userStatus, self.cookie)
        Log.info(ret)
        return ret.list[0].id

    def credit_user_getpage_web(self):
        '''检索页面用户'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_creditName = self.file_data.get('creditName_web')
        search_LIKE_creditUser = self.file_data.get('creditUser_web')
        search_LIKE_creditOrgCode = self.file_data.get('creditOrgCode')
        search_EQ_userClass = self.file_data.get('userClass')
        search_IN_deptCode = self.file_data.get('deptCode')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        ret = PerCreditUserRequest.per_getpage(curPage, maxSize, search_LIKE_creditName, search_LIKE_creditUser,
                                               search_LIKE_creditOrgCode, search_EQ_userClass, search_IN_deptCode,
                                               search_EQ_userStatus, self.cookie)
        Log.info(ret)
        return ret.list[0].id

    def role_get_page(self):
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_LIKE_name = self.file_data.get('role_name')
        search_EQ_roleType = self.file_data.get('add_roleType')
        ret = RoleRequest.role_getpage(curPage,maxSize,search_LIKE_name,search_EQ_roleType,self.cookie)
        self.assertEqual(search_LIKE_name,ret.list[0].name)
        return ret.list[0].id

    #新建用户--个人监管权限--企业监管权限--第一次登陆--修改密码
    def test_c_create_user(self):
        '''新建用户'''
        userName1 = self.file_data.get('userName1')
        nickName1 = self.file_data.get('nickName1')
        idCard = self.file_data.get('idCard')
        orgId = self.file_data.get('orgId')
        userType = self.file_data.get('userType')
        telephone = self.file_data.get('telephone')
        mobile = self.file_data.get('mobile')
        weiChat = self.file_data.get('weiChat')
        userEmail = self.file_data.get('userEmail')
        orgPhone = self.file_data.get('orgPhone')
        postCode = self.file_data.get('postCode')
        address = self.file_data.get('address')
        deptName = self.file_data.get('deptName')
        ipbindflag = self.file_data.get('ipbindflag')
        ipbindnum = self.file_data.get('ipbindnum')
        macbindflag = self.file_data.get('macbindflag')
        macbindnum = self.file_data.get('macbindnum')
        mark = self.file_data.get('mark')
        lockFlag = self.file_data.get('lockFlag')
        resetFlag = self.file_data.get('resetFlag')
        stopFlag = self.file_data.get('stopFlag')
        roleIds = TestSetUpUserMenu().role_get_page()
        assignRoleIds = TestSetUpUserMenu().role_get_page()
        ret = UserRequest.create(userName1,
                                nickName1,
                                idCard,
                                orgId,
                                userType,
                                telephone,
                                mobile,
                                weiChat,
                                userEmail,
                                orgPhone,
                                postCode,
                                address,
                                deptName,
                                ipbindflag,
                                ipbindnum,
                                macbindflag,
                                macbindnum,
                                mark,
                                lockFlag,
                                resetFlag,
                                stopFlag,
                                roleIds,
                                assignRoleIds,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertEqual('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_d_per_userattr(self):
        '''个人监管权限'''
        userName1 = self.file_data.get('userName1')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.per_userattr(userName1,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)

        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_e_ent_userattr(self):
        '''企业监管权限'''
        userName1 = self.file_data.get('userName1')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.ent_userattr(userName1,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def login_first1(self):
        '''用户首次登录'''
        username = self.file_data.get('userName1')
        password = self.file_data.get('password')
        phonecode = self.file_data.get('phonecode')
        captcha = self.file_data.get('captcha')
        mode = self.file_data.get('mode')
        needPWD = self.file_data.get('needPWD')
        ret = UserRequest.login_cookie(username,password,phonecode,captcha,mode,needPWD)
        Log.info(ret)
        return ret

    def test_f_update_pwd(self):
        '''修改密码'''
        password = self.file_data.get('password')
        newpassword  = self.file_data.get('new')
        new = self.file_data.get('new')
        cookie = TestSetUpUserMenu().login_first1()
        ret = UserRequest.updatepasswd(password,
                                        newpassword,
                                        new,cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('操作成功',ret.msg)


    #第二个用户

    def test_g_create_user(self):
        '''新建用户'''
        userName2 = self.file_data.get('userName2')
        nickName2 = self.file_data.get('nickName2')
        idCard = self.file_data.get('idCard')
        orgId = self.file_data.get('orgId')
        userType = self.file_data.get('userType')
        telephone = self.file_data.get('telephone')
        mobile = self.file_data.get('mobile')
        weiChat = self.file_data.get('weiChat')
        userEmail = self.file_data.get('userEmail')
        orgPhone = self.file_data.get('orgPhone')
        postCode = self.file_data.get('postCode')
        address = self.file_data.get('address')
        deptName = self.file_data.get('deptName')
        ipbindflag = self.file_data.get('ipbindflag')
        ipbindnum = self.file_data.get('ipbindnum')
        macbindflag = self.file_data.get('macbindflag')
        macbindnum = self.file_data.get('macbindnum')
        mark = self.file_data.get('mark')
        lockFlag = self.file_data.get('lockFlag')
        resetFlag = self.file_data.get('resetFlag')
        stopFlag = self.file_data.get('stopFlag')
        roleIds = TestSetUpUserMenu().role_get_page()
        assignRoleIds = TestSetUpUserMenu().role_get_page()
        ret = UserRequest.create(userName2,
                                nickName2,
                                idCard,
                                orgId,
                                userType,
                                telephone,
                                mobile,
                                weiChat,
                                userEmail,
                                orgPhone,
                                postCode,
                                address,
                                deptName,
                                ipbindflag,
                                ipbindnum,
                                macbindflag,
                                macbindnum,
                                mark,
                                lockFlag,
                                resetFlag,
                                stopFlag,
                                roleIds,
                                assignRoleIds,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertEqual('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_h_per_userattr(self):
        '''个人监管权限'''
        userName2 = self.file_data.get('userName2')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.per_userattr(userName2,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)

        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_i_ent_userattr(self):
        '''企业监管权限'''
        userName2 = self.file_data.get('userName2')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.ent_userattr(userName2,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def login_first2(self):
        '''用户首次登录'''
        username = self.file_data.get('userName2')
        password = self.file_data.get('password')
        phonecode = self.file_data.get('phonecode')
        captcha = self.file_data.get('captcha')
        mode = self.file_data.get('mode')
        needPWD = self.file_data.get('needPWD')
        ret = UserRequest.login_cookie(username,password,phonecode,captcha,mode,needPWD)
        Log.info(ret)
        return ret

    def test_j_update_pwd(self):
        '''修改密码'''
        password = self.file_data.get('password')
        newpassword  = self.file_data.get('new')
        new = self.file_data.get('new')
        cookie = TestSetUpUserMenu().login_first2()
        ret = UserRequest.updatepasswd(password,
                                        newpassword,
                                        new,cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('操作成功',ret.msg)


        #第三个用户

    #第三个用户
    def test_k_create_user(self):
        '''新建用户'''
        userName3 = self.file_data.get('userName3')
        nickName3 = self.file_data.get('nickName3')
        idCard = self.file_data.get('idCard')
        orgId = self.file_data.get('orgId')
        userType = self.file_data.get('userType')
        telephone = self.file_data.get('telephone')
        mobile = self.file_data.get('mobile')
        weiChat = self.file_data.get('weiChat')
        userEmail = self.file_data.get('userEmail')
        orgPhone = self.file_data.get('orgPhone')
        postCode = self.file_data.get('postCode')
        address = self.file_data.get('address')
        deptName = self.file_data.get('deptName')
        ipbindflag = self.file_data.get('ipbindflag')
        ipbindnum = self.file_data.get('ipbindnum')
        macbindflag = self.file_data.get('macbindflag')
        macbindnum = self.file_data.get('macbindnum')
        mark = self.file_data.get('mark')
        lockFlag = self.file_data.get('lockFlag')
        resetFlag = self.file_data.get('resetFlag')
        stopFlag = self.file_data.get('stopFlag')
        roleIds = TestSetUpUserMenu().role_get_page()
        assignRoleIds = TestSetUpUserMenu().role_get_page()
        ret = UserRequest.create(userName3,
                                nickName3,
                                idCard,
                                orgId,
                                userType,
                                telephone,
                                mobile,
                                weiChat,
                                userEmail,
                                orgPhone,
                                postCode,
                                address,
                                deptName,
                                ipbindflag,
                                ipbindnum,
                                macbindflag,
                                macbindnum,
                                mark,
                                lockFlag,
                                resetFlag,
                                stopFlag,
                                roleIds,
                                assignRoleIds,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertEqual('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_l_per_userattr(self):
        '''个人监管权限'''
        userName3 = self.file_data.get('userName3')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.per_userattr(userName3,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)

        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def test_m_ent_userattr(self):
        '''企业监管权限'''
        userName3 = self.file_data.get('userName3')
        printPermit = self.file_data.get('printPermit')
        printAmount = self.file_data.get('printAmount')
        savePermit = self.file_data.get('savePermit')
        creditUser = TestSetUpUserMenu().credit_user_getpage_web()
        interfaceCreditUser  = TestSetUpUserMenu().credit_user_getpage_api()
        whiteList = self.file_data.get('whiteList')
        ret = UserRequest.ent_userattr(userName3,
                                        printPermit,
                                        printAmount,
                                        savePermit,
                                        creditUser,
                                        interfaceCreditUser,
                                        whiteList,self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)
        self.assertIsNotNone(ret.objectData)

    def login_first3(self):
        '''用户首次登录'''
        username = self.file_data.get('userName3')
        password = self.file_data.get('password')
        phonecode = self.file_data.get('phonecode')
        captcha = self.file_data.get('captcha')
        mode = self.file_data.get('mode')
        needPWD = self.file_data.get('needPWD')
        ret = UserRequest.login_cookie(username,password,phonecode,captcha,mode,needPWD)
        Log.info(ret)
        return ret

    def test_n_update_pwd(self):
        '''修改密码'''
        password = self.file_data.get('password')
        newpassword  = self.file_data.get('new')
        new = self.file_data.get('new')
        cookie = TestSetUpUserMenu().login_first3()
        ret = UserRequest.updatepasswd(password,
                                        newpassword,
                                        new,cookie)
        Log.info(ret)
        self.assertEqual('00000000',ret.code)
        self.assertEqual('操作成功',ret.msg)



















if __name__ == "__main__":
    pass